package com.yzkj.cpjxc.business.framework.utils;

import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Service;

/**
 * 提供获取spring管理的bean的工具类
 */
@Service
public class ContextUtils implements ApplicationContextAware {

	private static ApplicationContext context;

	/**   
	 * 实现ApplicationContextAware接口的context注入函数, 将其存入静态变量.   
	 */
	public void setApplicationContext(ApplicationContext applicationContext) {
		context = applicationContext;
	}

	public static ApplicationContext getApplicationContext() {
		return context;
	}

	/**   
	 * 从静态变量ApplicationContext中取得Bean, 自动转型为所赋值对象的类型.   
	 */
	public static Object getBean(String name) {
		return context.getBean(name);
	}
	
}
